#include "ctrl_prog.h"

#define fifo_path       "/home/debian/qt_test/fifo"
#define course_path     "/home/debian/tftp_dir/mk_fifo"

extern uint8_t Tx_data[6];

Ctrl_prog::Ctrl_prog(QObject *parent) : QObject(parent)
{
    
        //判断fifo是否存在  不存在则创建
        ret = access(fifo_path, F_OK);
        if( ret < 0 ){
            ret = mkfifo(fifo_path, O_RDWR );
            if( ret < 0 )
                printf("qt FIFO file creat error!\n");
        }
        fifo_fd = open(fifo_path, O_RDWR);
        if( fifo_fd < 0 ){
            printf("qt FIFO file open error!\n");
            exit(-1);
        }
        //创建子进程 运行控制程序
        pid_t pid;

        pid = fork();
        if( pid == 0 ){
            ret = execl(course_path, " ", NULL);
            if( ret == -1 ){
                printf("course create error!\n");
                exit(-1);
            }
        }

}

void Ctrl_prog::qt_send(unsigned char *buf)
{
    ret = write(fifo_fd, buf, 6);
    if( ret != 6){
        printf("fifo write error!\n");
    }
}


